/*
 * $Id: session.h 77 2008-02-20 08:56:12Z jasta $
 *
 * Copyright (C) 2008 Josh Guilfoyle <jasta@devtcg.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 */

#ifndef __SESSION_H
#define __SESSION_H

/*****************************************************************************/

struct anchor
{
	time_t last;
	time_t next;
};

typedef struct five_session
{
	SmlDsSession *dsession;

	/* SQLite3 is only recently thread-safe, and prior to version 3.3.1 did not
	 * permit connections opened in one thread to be used by another.  To avoid
	 * this case, we will open a separate connection for each thread (which is
	 * spawned for each session). */
	sqlite3 *dbconn;

	SmlAlertType type;

	struct anchor client;
	struct anchor server;

	unsigned int errors;
} FiveSession;

typedef struct five_change
{
	SmlChangeType type;
	sqlite_int64 guid;
	sqlite_int64 luid;
	unsigned char *data;
	size_t datasz;
	char *mime;
} FiveChange;

/*****************************************************************************/

FiveSession *five_session_new(SmlDsSession *dsess);
void five_session_free(FiveSession *fsess);

gboolean five_session_update_anchors(FiveSession *fsess);
GList *five_session_get_changes(FiveSession *fsess, unsigned int *len);

/*****************************************************************************/

#endif /* __SESSION_H */
